import { createRouter, createWebHistory } from 'vue-router';
// 配备路由
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {path:'/login',component:()=>import('@/views/LoginPage.vue'),meta:{title:'登录'}},
    {path:'/', component:()=>import('@/components/IndexLayout.vue')},
    {path: '/student',component:()=>import('@/components/StudentLayout.vue'),
      children: [
      { path: '', component:()=>import('@/views/Student/HomePage.vue'),meta:{title:'首页'}},
      { path: 'settings', component:()=>import('@/views/Student/SettingsPage.vue'),meta:{title:'系统设置'}},
      {path:'question/channel',component:()=>import('@/views/Student/QuestionChannel.vue'),meta:{title:'题目列表'}},
      {path:'question/details/:title',component:()=>import('@/views/Student/QuestionDetails.vue'),meta:{title:'题目详情'}},
      {path:'question/result',component:()=>import('@/views/Student/QuestionDetailResult.vue'),meta:{title:'运行结果'}},
    ]
    },
    {
    path: '/teacher',component:()=>import('@/components/TeacherLayout.vue'),
    children: [
      { path: '',  component:()=>import('@/views/Student/HomePage.vue')},
      { path: 'communication', component:()=>import('@/views/Teacher/CommunicationPage.vue')},
      { path: 'settings',component:()=>import('@/views/Teacher/SettingsPage.vue')}
  ]},
  // { path: '/:pathMatch(.*)*', redirect: '/' }
 
],
  scrollBehavior(){
    return{top:0}
  }
})

// 路由守卫
router.beforeEach((to) => {
  // 设置页面标题
  document.title = to.meta.title || '小码智学';
});

export default router;